package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.CategoryBrandMapper;
import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName: CategotyBrandServiceImpl
 * @Package: com.atguigu.spzx.manager.service.impl
 * @Description
 * @Author 孤妤
 * @Date: 2023/12/8 9:43
 */
@Service
@Transactional
public class CategotyBrandServiceImpl implements CategoryBrandService {
    @Autowired
    private CategoryBrandMapper categoryBrandMapper;
    @Override
    @Transactional(readOnly = true)
    public PageInfo<CategoryBrand> findCategoryBrandPage(Integer pageNum, Integer pageSize, CategoryBrandDto categoryBrandDto) {
        PageHelper.startPage(pageNum,pageSize);
        List<CategoryBrand> categoryBrandList = categoryBrandMapper.selectCategoryBrandPage(categoryBrandDto);
        return new PageInfo<>(categoryBrandList);
    }

    @Override
    public void addCategoryBrand(CategoryBrandDto categoryBrandDto) {
        categoryBrandMapper.insertCategoryBrand(categoryBrandDto);
    }

    @Override
    public void changeCategoryBrandById(CategoryBrand categoryBrand) {
        categoryBrandMapper.updateCategoryBrandById(categoryBrand);
    }

    @Override
    public void removeCategoryBrandById(Long id) {
        categoryBrandMapper.deleteCategoryBrandById(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Brand> FindBrandByCategoryId(Long id) {
        return categoryBrandMapper.selectBrandByCategoryId(id);
    }
}
